package order.server;

import order.dao.OrderInfo;
import order.dao.ProductInfo;
import order.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;


@Service
public class OrderServer {

    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RestTemplate restTemplate;

    //使用注解@LoadBalanced来均衡负载
    public OrderInfo getOrderById(int orderId) {

        OrderInfo orderInfo = orderMapper.selectById(orderId);

        //他会根据这个product-server来获取到对应的服务 通过getHost来得到
        String url = "http://product-server/product/"+ orderInfo.getProductId();

        ProductInfo forObject = restTemplate.getForObject(url, ProductInfo.class);

        orderInfo.setProductInfo(forObject);

        return orderInfo;
    }
}